# Maintainer: David Runge <dvzrv@archlinux.org>
# Contributor: Tobias Powalowski <tpowa@archlinux.org>
# Contributor: judd <jvinet@zeroflux.org>

pkgname=alsa-utils
pkgver=1.2.10
pkgrel=1
pkgdesc="Advanced Linux Sound Architecture - Utilities"
arch=(loong64 x86_64)
url="https://www.alsa-project.org"
license=(GPL2)
depends=(
  gcc-libs
  glibc
  pciutils
  psmisc
)
makedepends=(
  alsa-lib
  docbook-xsl
  fftw
  libsamplerate
  ncurses
  python-docutils
  systemd
  xmlto
)
optdepends=(
  'bash: for alsa-info.sh and alsabat-test.sh'
  'fftw: for alsabat'
)
# we require /var/lib/alsa for state file
options=(emptydirs)
source=(https://www.alsa-project.org/files/pub/utils/$pkgname-$pkgver.tar.bz2{,.sig})
sha512sums=('22adedf6d491d7768d24f054262a9c12bc952049db8374e104c0477ebf84266dcbeb0a2a3a1765b89958073d341f64dedbae63e3cae66f4983a0424e5cb3243f'
            'SKIP')
b2sums=('077b4ad090c1ab40dd4fa22db01ae2a080ca849a5564dfe612654993297c80bd3584541c7e68aaad56c4c05538ba0de449e4677b1c4a9dfe56d8e11706c4ca35'
        'SKIP')
validpgpkeys=('F04DF50737AC1A884C4B3D718380596DA6E59C91') # ALSA Release Team (Package Signing Key v1) <release@alsa-project.org>

prepare() {
  cd $pkgname-$pkgver
  autoreconf -fiv
}

build() {
  local configure_options=(
    --prefix=/usr
    --disable-alsaconf
    --sbindir=/usr/bin
    --with-udev-rules-dir=/usr/lib/udev/rules.d
    --with-systemdsystemunitdir=/usr/lib/systemd/system
  )

  cd $pkgname-$pkgver
  ./configure "${configure_options[@]}"
  make
}

check() {
  make -k check -C $pkgname-$pkgver
}

package() {
  depends+=(
    alsa-lib libasound.so libatopology.so
    ncurses libformw.so libmenuw.so libncursesw.so libpanelw.so
    libsamplerate libsamplerate.so
  )

  make DESTDIR="$pkgdir" install -C $pkgname-$pkgver
  install -vDm 644 $pkgname-$pkgver/README.md -t "$pkgdir/usr/share/doc/$pkgname/"
  # dir where to save ALSA state
  install -vdm 755 "$pkgdir/var/lib/alsa/"
}
